/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import Entities.Artist;

import Entities.Song;
import java.util.Date;
import javax.persistence.*;
import java.util.List;

/**
 *
 * @author sebastian
 */
public class ArtistService {

    protected EntityManager em;

    public ArtistService(EntityManager em) {
        this.em = em;
    }

    public Artist createArtist(Long ID, String name, String lastName, 
            String picture, Date birthday, String birthPlace,
            List<Song> songEntitys) {
        Artist person = new Artist(ID);
        person.setName(name);
        person.setLastName(lastName);
        person.setPicture(picture);
        person.setBirthDate(birthday);
        person.setBirthPlace(birthPlace);
        person.setSongEntitys(songEntitys);
        
        em.persist(person);
        
        return person;
    }
    
    
    public void updateArtist(Long ID, String name, String lastName, 
            String picture, Date birthday, String birthPlace,
            List<Song> songEntitys) {
        Artist person = findArtist(ID);
        person.setName(name);
        person.setLastName(lastName);
        person.setPicture(picture);
        person.setBirthDate(birthday);
        person.setBirthPlace(birthPlace);
        person.setSongEntitys(songEntitys);
        
        em.persist(person);
    }   
        
    public void removeArtist(Long ID) {
        Artist person = findArtist(ID);
        if (person != null) {
            em.remove(person);
        }
    }

    public Artist findArtist(Long ID) {
        return em.find(Artist.class, ID);
    }

  
}

